(function(){
    angular.module('app').controller("agTradeCtrl",function($scope,$stateParams,proxy){
        $scope.obj={
            'sTime':getNowFormatDate() + " 00:00:00", //默认今天
            'eTime':getNowFormatDate() + " 23:59:59",

        };
        $scope.time = "今日";
        var id = $stateParams.id;
        //时间过滤
        $scope.chooseDate = function(sTime,eTime,type){
            if(sTime =='' && eTime==''){
                $scope.obj.sTime = '';
                $scope.obj.eTime = '';
            }else{
                $scope.obj.sTime = sTime+' '+'00:00:00';
                $scope.obj.eTime = eTime+' '+'23:59:59';
            }
            switch (type) {
                case 1:
                    $scope.time = "今日";
                    break;
                case 2:
                    $scope.time = "昨日";
                    break;
                case 3:
                    $scope.time = "最近7日";
                    break;
                case 4:
                    $scope.time = "最近14日";
                    break;
            }
            getList();
            getSum();
        };

        getList();
        getSum();

        function getList(current, pagesize) {
            var data = {
                'page': (current || 1)+"",
                'size': (pagesize || 20)+"",
                "filter": {
                    "relateAccount":id,
                    "action":"adverIn,adverOut",
                },
                'sTime' : $scope.obj.sTime,
                'eTime' : $scope.obj.eTime,
                "sort": ["cTime,1"],
            };
            proxy.proxy({
                url: STATIC_URL.domian+'/dsp/advertiser/transaction',
                data:data,
                load:true,
                success: function(res){
                    // 获得列表
                    $scope.list = res.data.data;
                    $("#pageToolbar").html("");
                    $('#pageToolbar').Paging({pagesize: pagesize || '20',current: current || '1',count:res.data.total,toolbar:true,'hash': false,
                        callback:getList});
                }
            })
        };

        function getSum() {
            //请求财务信息
            proxy.proxy({
                url: STATIC_URL.domian+'/dsp/rpt/consume/sum',
                data:{
                    "token":"",
                    "filter": {
                        "advertiserID":id // 广告主ID
                    },
                    'sTime' : $scope.obj.sTime,
                    'eTime' : $scope.obj.eTime,
                },
                success: function(res){
                    console.log(res);
                    $scope.obj.cost = res.data.data.cost;
                    $scope.obj.inCome = res.data.data.inCome;
                }
            })
        }
    })
})();